/* app/actions/detail.js */

import request from '../utils/request';

import {
	GET_GROUP_DETAIL,
	CREATE_GROUP,
	SEND_VALIDATE_CODE,
	ADD_SHOPPING_CART
}
from '../constants/actionTypes';

import groupActions from './group';

export function getProductDetail(params, onSuccess = (() => {}), onError = (() => {})) {
	var url = 'http://jsapi.tuan.ymatou.com/api/Tuan/GroupDetail';
	return {
		type: GET_GROUP_DETAIL,
		payload: {
			promise: request(url, { /*options*/ }, params),
			onSuccess,
			onError
		}
	}
}

export function createGroup(
	params, 
	onSuccess = (() => {}), 
	onError = (() => {}),
	onFinish = () => {}) {
	var url = 'http://jsapi.tuan.ymatou.com/api/Tuan/CreateGroup';
	return {
		type: CREATE_GROUP,
		payload: {
			promise: request(url, { /*options*/ }, params),
			onSuccess,
			onError,
			onFinish
		}
	}
}

export function joinGroup(
	params, 
	onSuccess = (() => {}), 
	onError = (() => {}),
	onFinish = () => {}) {
	var url = 'http://jsapi.tuan.ymatou.com/api/Tuan/JoinGroup';
	return {
		type: CREATE_GROUP,
		payload: {
			promise: request(url, { /*options*/ }, params),
			onSuccess,
			onError,
			onFinish
		}
	}
}

export function sendValidateCode(
	params, 
	onSuccess = (() => {}), 
	onError = (() => {}),
	onFinish = () => {}) {
	var url = 'http://login.ymatou.com/SendMobileValidateCode?type=1';
	return {
		type: SEND_VALIDATE_CODE,
		payload: {
			promise: request(url, { /*options*/ }, params),
			onSuccess,
			onError,
			onFinish
		}
	}
}

export function bindMobile(params, 
	onSuccess = (() => {}), 
	onError = (() => {})) {
	var url = 'http://login.ymatou.com/WeChatRegisterUser';
	return {
		type: SEND_VALIDATE_CODE,
		payload: {
			promise: request(url, { /*options*/ }, params),
			onSuccess,
			onError
		}
	}
}

export function addShoppingCart(
	params,
	onSuccess = (() => {}),
	onError = (() => {}),
	onFinish = () => {}) {
	var url = 'http://jsapi.preorder.ymatou.com/api/ShoppingCart/AddBuyNow';
	return {
		type: ADD_SHOPPING_CART,
		payload: {
			promise: request(url, { /*options*/ }, params),
			onSuccess,
			onError,
			onFinish
		}
	}
}